package com.pdwbdn.utils;

import org.apache.commons.exec.*;

public class ExecUtil {
    public static String exec(String cmd, String... args) {
        try {
            if (cmd == null) {
                return null;
            }
            if (args == null) {
                return null;
            }
            CommandLine command = CommandLine.parse(cmd);
            for (String arg : args) {
                command.addArgument(arg);
            }
            DefaultExecutor executor = DefaultExecutor.builder().get();
            executor.setExitValue(0);
            DefaultExecuteResultHandler handler = new DefaultExecuteResultHandler();
            executor.execute(command, handler);
            return "ok";
        } catch (Throwable t) {
            System.err.println(t.toString());
            return t.toString();
        }
    }
}
